package com.itheima.tanhua.controller;

import com.itheima.tanhua.domain.Settings;
import com.itheima.tanhua.service.SettingsService;
import com.itheima.tanhua.vo.PageResult;
import com.itheima.tanhua.vo.SettingsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Lff
 * @date 2022/3/25
 * 处理通用设置
 */
@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;

    /**
     * 查询用户通用设置
     *
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity getSettings() {
        SettingsVo settingsForId = settingsService.getSettingsForId();
        return ResponseEntity.ok(settingsForId);
    }


    /**
     * 设置陌生人问题
     *
     * @param map
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map) {
        //获取问题
        String content = (String) map.get("content");
        //调用Service来实现功能
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 更新通用设置
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity setting(@RequestBody Settings settings) {
        //调用service来实现设置更新
        settingsService.updateSetting(settings);
        return ResponseEntity.ok(null);
    }

    /**
     * blacklist
     * 获取黑名单列表
     *
     * @return
     */
    @GetMapping("/blacklist")
    public ResponseEntity getBlackList(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10")Integer pageSize) {
        PageResult pr = settingsService.findBlackPage(page, pageSize);
        return ResponseEntity.ok(pr);
    }

    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity removeBlack(@PathVariable("uid") Long blackUserId) {
        //调用api进行移除
        settingsService.removeBlack(blackUserId);
        return ResponseEntity.ok(null);
    }
}
